package com.diaohw.module.file.mapper;

import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.diaohw.module.file.obj.entity.CatalogDO;
import com.diaohw.module.file.obj.query.CatalogQuery;
import com.diaohw.module.file.obj.tables.CatalogDef;
import com.mybatisflex.core.BaseMapper;
import com.mybatisflex.core.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;

/**
 * 目录 映射层。
 *
 * @author D-Hw
 * @since 2024-11-22 17:21:01
 */
@Mapper
public interface CatalogMapper extends BaseMapper<CatalogDO> {


    static QueryWrapper createWrapper(CatalogQuery query) {
        QueryWrapper wrapper = QueryWrapper.create();
        wrapper.and(CatalogDef.CATALOG.SORT.eq(query.getSort()).when(ObjUtil.isNotNull(query.getSort())));
        wrapper.and(CatalogDef.CATALOG.PARENT_ID.like(query.getParentId()).when(StrUtil.isNotBlank(query.getParentId())));
        wrapper.and(CatalogDef.CATALOG.CATALOG_CODE.like(query.getCatalogCode()).when(StrUtil.isNotBlank(query.getCatalogCode())));
        wrapper.and(CatalogDef.CATALOG.CATALOG_TYPE.eq(query.getCatalogType()).when(query.getCatalogType() != null));
        wrapper.and(CatalogDef.CATALOG.CATALOG_NAME.like(query.getCatalogName()).when(StrUtil.isNotBlank(query.getCatalogName())));
        return wrapper;
    }
}
